package com.jms.fu.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jms.fu.exception.DAOException;
import com.jms.fu.model.bo.AppBO;

public class AddCommentAction extends Action{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		HttpSession session = request.getSession();
		PrintWriter out=null;
		try {
			out = response.getWriter();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		if(request.getParameter("appid")==null||request.getParameter("comment")==null
				||"".equals(request.getParameter("comment"))){
			return null;
		}
		if(session.getAttribute("username")==null){
			out.print("login");
		}
		String username = (String)session.getAttribute("username");
		int appId = Integer.parseInt(request.getParameter("appid"));
		String comment = request.getParameter("comment");
		
		AppBO appbo = new AppBO();
		try {
			appbo.addComment(appId, username, comment);
			
		} catch (DAOException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
}
